<?php
/*
 *  supplier 供货商添加类
 *
 *  @param $c 一般是类名
 *  @param $a 一般是方法名
 */
class account extends Admin {

    private $tab = array( 'storeTemplate' => '店铺模版管理','logistics' => '物流信息管理','size'=>'尺码信息','materials'=>'店装素材信息','Account'=>'公共帐户');

    private $accountType =array('新浪微博','腾讯微博','论坛推广','QQ群','百度知道');

    public function index( $c, $a ) {
        $type = G( 'type', 'storeTemplate' );
        $method = "{$a}_{$type}";
        $this->$method( $c, $a, $type );
    }
    public function index_storeTemplate( $c, $a ) {
        $type = G( 'type', 'storeTemplate' );
        $templateId = G('templateId',0);
        header( "location:?c=commonInfo&type=storeTemplate");

    }
    public function index_logistics( $c, $a ) {
        $type = G( 'type', 'logistics' );
        header( "location:?c=commonInfo&type=logistics");
    }
    public function index_account( $c, $a ) {
        $type = G( 'type', 'account' );
        include $this->display('account');
    }

    public function index_size( $c, $a ) {
        $type = G( 'type', 'size' );
        header( "location:?c=commonInfo&type=size");
    }
    public function index_materials( $c, $a ) {
        $type = G( 'type', 'materials' );
        header( "location:?c=commonInfo&type=materials");
    }
    public function  lookAccount($c,$a)
    {
        $type = G( 'key1' );
        $this->table = 'refClothSize';
        $type = G( 'type', 'account' );
        $result = $this->find(array('addrType'=>$type));

        include $this->display( $c );
    }





    public function addAccount($c,$a,$args)
    {
        include $this->display( $c );
    }



    public function edit( $c, $a ) {
        if ( !$id = intval( G( 'id' ) ) ) {
            $this->error();
            exit;
        }

        $this->table = 'accountInfo'; // 数据库表名
        $result = $this->find( array( 'id' => $id ) ); // 查找数据
        include $this->display( $c ); // 加载模板
    }





    public function save() {
        # 获取表单数据
        foreach ( $_POST as $key => $val ) {
            $rows[ $key ] = htmlspecialchars( trim( $val ) );
        }

        # 注意 表单字段必须跟数据库表字段名一样
        $this->table = 'accountInfo'; // 数据库表名
        if ( $id = intval( G( "id" ) ) ) {
            $msg = $this->update( array( 'id' => $id ), $rows ) ? 'success' : 'failed';  //更新供货商
        } else {
            $msg = $this->create( $rows ) ? 'success' : 'failed';                         // 添加供货商
        }
        exit( $msg );
    }
}